package com.wanmait.translate.dto;

import com.wanmait.translate.dto.audit.AuditContentInterface;
import com.wanmait.translate.utils.AuditEnum;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/*
 * @Author huweibin
 * @Description 表明审核的类别与内容类的对应关系，内容可以是出差审核、授权申请等等（与枚举类中的类别对应），
 * @Date 21:09 2020/11/23
 **/
public  class TypeContent {
    //类别，如出差审核
    private  String type;
    //类别的中文名
    private  String typeName;
    //类别的ID
    private  Integer typeId;
   //对应的所有状态信息
    private List<State> states=new ArrayList<>();
    //可选 ：所有的内容
    private List<AuditContentInterface> list=new ArrayList<>();


    //构造器
    public  TypeContent(AuditEnum auditEnum){
        this.type = auditEnum.getName();
        this.typeName = auditEnum.getTypeName();
        this.typeId = auditEnum.ordinal();
    }
    //静态获得所有类型所有状态的一个空模板,仅用于遍历
    public static List<TypeContent> getAllTypeContent(){
        ArrayList<TypeContent> list = new ArrayList<>();
        for (AuditEnum value : AuditEnum.values()) {
            TypeContent typeContent = new TypeContent(value);
            Map<Integer, String> states = value.getStates();
            for (Map.Entry<Integer, String> entry : states.entrySet()) {
                typeContent.addState(entry.getValue(),entry.getKey(),null);
            }
            list.add(typeContent);
        }
        return list;
    }




    //获得当前审核类型的枚举类
    public AuditEnum getEnum(){
        return AuditEnum.values()[typeId];
    }
    //添加一种状态
    public void addState(String name, Integer stateId, Integer count){
        states.add(new State(name,stateId,count));
    }
    //根据状态获得指定的数量
    public Integer getStateCount(State state){
        for (State state1 : this.getStates()) {
            if (state.stateId.equals(state1.stateId)){
                return state1.getCount();
            }
        }
        return null;
    }
    //向list中追加
    public void addList(List res){
        list.addAll(res);
    }

    //内部状态类
    public static class State{
        //当前状态名
        private String name;
        //状态的Id(对应枚举类的索引)
        private Integer stateId;
        //此状态的数量
        private  Integer count;


        public State(String name, Integer stateId, Integer count) {
            this.name = name;
            this.stateId = stateId;
            this.count = count;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public Integer getStateId() {
            return stateId;
        }

        public void setStateId(Integer stateId) {
            this.stateId = stateId;
        }

        public Integer getCount() {
            return count;
        }

        public void setCount(Integer count) {
            this.count = count;
        }

        @Override
        public String toString() {
            return "State{" +
                    "name='" + name + '\'' +
                    ", stateId=" + stateId +
                    ", count=" + count +
                    '}';
        }
    }







    @Override
    public String toString() {
        return "TypeContent{" +
                "type='" + type + '\'' +
                ", typeName='" + typeName + '\'' +
                ", typeId=" + typeId +
                ", states=" + states +
                ", list=" + list +
                '}';
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getTypeName() {
        return typeName;
    }

    public void setTypeName(String typeName) {
        this.typeName = typeName;
    }

    public Integer getTypeId() {
        return typeId;
    }

    public void setTypeId(Integer typeId) {
        this.typeId = typeId;
    }

    public List<State> getStates() {
        return states;
    }

    public void setStates(List<State> states) {
        this.states = states;
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

}

